home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
quodlibet
/
util
/
uri.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2014-12-31
|
4KB
|
116 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
import os
import re
from urllib import url2pathname, quote_plus, unquote_plus
from urlparse import urlparse, urlunparse
from quodlibet.util.path import fsdecode, pathname2url
class URI(str):
'''A full URI string. This object provides several convenience
attributes to access data from the urlparse and urllib modules.
URIs inherit from str, and so any method that works on a str
works on a URI.
URIs are not closed under concatenation, slicing, and so on. Neither
are these URI objects; such operations will return strs.'''
def __new__(klass, value, escaped = True):
'''Create a new URI object. By default, the URI is assumed to be
escaped already. Pass escaped=False if you need the URI escaped
(this is imperfect now).
The URI returned will be equivalent, but not necessarily
equal, to the value passed in.'''
value = re.sub('^([A-Za-z]+):///+', '\\1:///', value)
values = list(urlparse(value))
if not escaped:
values[2] = quote_plus(values[2], safe = '/~')
value = urlunparse(values)
obj = str.__new__(klass, value)
if not (obj.scheme) or not (len(obj.scheme) > 1):
raise ValueError("URIs must have a scheme, such as 'http://'")
if not obj.netloc or obj.path:
raise ValueError('URIs must have a network location or path')
return obj
def frompath(klass, value):
'''Construct a URI from an unescaped filename.'''
return klass('file://' + pathname2url(value), escaped = True)
frompath = classmethod(frompath)
def scheme(self):
"""URI scheme (e.g. 'http')"""
return urlparse(self)[0]
scheme = property(scheme)
def netloc(self):
"""URI network location (e.g. 'example.com:21')"""
return urlparse(self)[1]
netloc = property(netloc)
def path(self):
"""URI path (e.g. '/~user')"""
return urlparse(self)[2]
path = property(path)
def params(self):
'''URI parameters'''
return urlparse(self)[3]
params = property(params)
def query(self):
"""URI query string (e.g. 'foo=bar&a=b')"""
return urlparse(self)[4]
query = property(query)
def fragment(self):
"""URI fragment ('foo' in '#foo')"""
return urlparse(self)[5]
fragment = property(fragment)
def unescaped(self):
'''an unescaped str (not URI) version of the URI'''
values = list(urlparse(self))
values[2] = unquote_plus(values[2])
return urlunparse(values)
unescaped = property(unescaped)
def filename(self):
'''a local filename equivalent to the URI'''
if self.scheme != 'file':
raise ValueError('only the file scheme supports filenames')
if self.netloc:
raise ValueError('only local files have filenames')
if os.name == 'nt':
return fsdecode(url2pathname(self.path))
return None(self.path)
filename = property(filename)
def is_filename(self):
'''True if the URI is a valid (not necessarily existing)
local filename
'''
if self.scheme == 'file':
pass
return not (self.netloc)
is_filename = property(is_filename)
def __repr__(self):
return '<%s %r>' % (type(self).__name__, self.unescaped)